package wh.Awa开小车;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2022/12/20 21:17
 * @description:
 * @version:
 */
public class Solution2 {
    static int m = 4;
    static int n = 4;
    static int x = 2;
    static int y = 2;
    static char temp = '.';
    static char[][] arr = new char[m][n];
    static int count = 0;
    public  static void main(String[] args) {
        List<Character> list = new ArrayList<>();
        list.add('U');
        list.add('D');
        list.add('L');
        list.add('R');
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                arr[i][j] = list.get(new Random().nextInt(4));
            }
        }
        while (solve()){
            System.out.println("x====>"+x);
            System.out.println("y====>"+y);
        }
        System.out.println(count-1);
    }

    public static boolean solve() {
        if (arr[x][y] != '.'){
            if (arr[x][y] != temp){
                count++;
                temp=arr[x][y];
            }
            arr[x][y] = '.';
        }
        if (temp=='D')x++;
        else if(temp=='U')x--;
        else if(temp=='L')y--;
        else if(temp=='R')y++;
        return x>=0&&x<=n-1&&y>=0&&y<=m-1;
    }
}
